package com.spica.platform.base.encrypt.encryptbody.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum DecryptRtnCodEnum implements IErrorCode {
    UN_KNOWN_DECRYPT_ERROR("BASE_DECRYPT_00000", "未知解密异常"),
    ENHANCE_DECRYPT_ERROR("ENHANCE_DECRYPT_00001","Decrypting data failed. (解密数据失败)"),
    ENHANCE_DECRYPT_UNDEFINED_ERROR("ENHANCE_DECRYPT_00002", "Decryption method is not defined. (解密方式未定义)"),
    ENHANCE_DECRYPT_ERROR_03("ENHANCE_DECRYPT_00003", "Unable to get request body data, please check if the sending data body or request method is in compliance with the specification. (无法获取请求正文数据，请检查发送数据体或请求方法是否符合规范。)"),
    ENHANCE_DECRYPT_ERROR_04("ENHANCE_DECRYPT_00004", "Decryption error, " + "please check if the selected source data is encrypted correctly. (解密错误，请检查选择的源数据的加密方式是否正确。)"),
    ENHANCE_DECRYPT_ERROR_05("ENHANCE_DECRYPT_00005", "The string is converted to a stream format exception. Please check if the format such as encoding is correct." + " (字符串转换成流格式异常，请检查编码等格式是否正确。)"),
    ;
    private String rtnCod;
    private String rtnMsg;

    DecryptRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    };
    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(DecryptRtnCodEnum.values())
                .filter(decryptRtnCodEnum -> StringUtil.equals(decryptRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(DecryptRtnCodEnum.UN_KNOWN_DECRYPT_ERROR);
    }
}
